package car;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NewServlet extends HttpServlet {

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	perform(req,resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	perform(req,resp);
	
	}
	private void perform(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException{
		req.setCharacterEncoding("UTF-8");
		String number = req.getParameter("number");
		String name = req.getParameter("name");
		String maker = req.getParameter("maker");
		System.out.println(number);
		System.out.println(name);
		System.out.println(maker);
		//Carオブジェクトを生成する
		Car car =new Car();
		car.setNumber(number);
		car.setName(name);
		car.setMaker(maker);	
		//CarListに追加する
		CarList.add(car);
		//一覧表を表示する（画面遷移）
		resp.sendRedirect("index.jsp");
	}
}
